package com.demo.consumer.controller.dept;

import com.demo.consumer.controller.apm.ApmDeomController;
import com.demo.consumer.pojo.Dept;
import com.demo.consumer.service.DeptMapperService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DeptController {

    private static final Logger log = LoggerFactory.getLogger(ApmDeomController.class);

    @Autowired
    DeptMapperService deptMapperService;

    @PostMapping("/dept/add")
    public boolean addDept(Dept dept){
        //insert into dept(dname, db_source) values (#{dname},DATABASE());
        log.info("/dept/add call add api!");
        return deptMapperService.addDept(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept queryById(@PathVariable("id") Integer id){
        //select * from dept where deptno = #{deptno};
        log.info("/dept/get/{} call get api!", id);
        return deptMapperService.queryById(id);
    }

    @GetMapping ("/dept/list")
    public List<Dept> queryAll(){
        //select * from dept;
        log.info("/dept/list call list api!");
        return deptMapperService.queryAll();
    }

    @GetMapping ("/dept/delete/{id}")
    public boolean deleteDept(@PathVariable("id") Integer id){
        //delete from dept where deptno = #{deptno};
        log.info("/dept/delete/{} call delete api!",id);
        return deptMapperService.deleteDept(id);
    }

    @GetMapping("/dept/descdeptno")
    public Integer descDeptno() {
        //select deptno from dept order by deptno desc limit 1;
        log.info("/dept/descdeptno call descdeptno api!");
        return deptMapperService.descDeptno();
    }

}
